import './public-path'
import Vue from 'vue'
import App from './App.vue'
import { routes } from './router'
import store from './store'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
Vue.config.productionTip = false

export let instance = null
export let router = null

function render({ props = {} }) {
  const { container, contentOnly } = props
  console.log('container:', container)
  router = new VueRouter({
    routes,
  })

  instance = new Vue({
    router,
    store,
    render: (h) => h(App),
  })
  instance.$mount(container ? container.querySelector('#app') : '#app')
}

if (!window.__POWERED_BY_QIANKUN__) {
  render({})
}

export async function bootstrap() {
  console.log('[p2项目]：初始化')
}

export async function mount(props) {
  console.log('[p2项目]：挂载', props)
  render(props)
}

export async function unmount() {
  console.log('[p2项目]：注销')
  instance.$destroy()
  instance.$el.innerHTML = ''
  instance = null
  router = null
}
